
<style>
    .ui-dialog{z-index:1000;}
</style>

<?php include_once 'common/header.php'; ?>
<!-- admin_main -->
<div class="admin_main">
    <!-- Admin_top end -->
    <?php include_once 'common/borrow_left.php'; ?>
    <!-- Admin_Left End -->
    <div class="admin_right">
        <div class="admin_right_title">
            <strong>贷款管理</strong> &gt;&gt; 编辑担保机构
        </div>
        <div class="admin_right_info">
            <div class="payonline_form">
                <form action="/ychadmin/guarantee/add/" method="post" id="gruaranteeForm"
                      name="gruaranteeForm" enctype="multipart/form-data">
                    <input  type="hidden" name="id" id="id" value="<?php echo $guarantee['id']; ?>"/>
                    <input  type="hidden" name="act" id="act" value="edit"/>
                    <dl class="online_dl">
                        <dt>机构类型名称：</dt>
                        <dd>
                            <select name="type" id="type" onchange="changeType();">
                                <option value="0">请选择</option>
                                <?php foreach ($borrow_guarantee as $key => $val) { ?>
                                    <option value="<?php echo $key; ?>" <?php if ($guarantee['type'] == $key) { ?>selected<?php } ?>><?php echo $val; ?></option>
                                <?php } ?>
                            </select>
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>前台是否可选：</dt>
                        <dd>
                        <input type="checkbox" name="isActive" id="isActive" <?php if ($guarantee['isActive'] == 1){?>checked="true"<?php }?>>
                        </dd>
                    </dl>

                    <dl class="online_dl">
                        <dt>担保机构名称：</dt>
                        <dd>
                            <input type="text" name="name" id="name" size="50"  value="<?php echo $guarantee['name']; ?>" />
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>机构别名：</dt>
                        <dd>
                            <input type="text" name="alias" id="name" size="50"  value="<?php echo $guarantee['alias']; ?>" />
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>注册资金：</dt>
                        <dd>
                            <input type="text" name="account" id="account" size="50"  value="<?php echo $guarantee['account']; ?>" />
                            <span id="accountTip"></span>
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>所属省市：</dt>
                        <dd>
                            <select name="province" id="province" onchange="changeCity(this.value, 'city');">
                                <option value="">请选择</option>
                            </select>
                            <select name="city" id="city" onchange="changeCity(this.value, 'area');"><option value="">请选择</option></select>
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>详细地址：</dt>
                        <dd>
                            <textarea name="address" id="address" style="width:400px; height:50px;"><?php echo $guarantee['address']; ?></textarea>
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>联系电话：</dt>
                        <dd>
                            <input type="text" name="contact" id="contact" size="50"  value="<?php echo $guarantee['contact']; ?>" />
                        </dd>
                    </dl>
                    <dl class="online_dl">
                        <dt>公司网址：</dt>
                        <dd>
                            <input type="text" name="web" id="web" size="50"  value="<?php echo $guarantee['web']; ?>" />
                        </dd>
                    </dl>


                    <dl class="online_dl" style="height:180px;">
                        <dt>合作金融机构相关图片：</dt>
                        <dd>
                            <div class="mod">
                                <input type="hidden" id="att_id" name="att_id" />
                                <span id="logoimgTip"><a  href="javascript:;" onclick="add_att();" class="addtr">添加机构相关材料</a></span>
                                <ul id="guarantee_att">
                                    <?php
                                    if ($att_list) {
                                        foreach ($att_list as $av) {
                                            ?>
                                            <li id="att_litpic_<?php echo $av['id'] ?>"><a target="_blank" href="/<?php echo $av['litpic'] ?>"><img src="/<?php echo $av['litpic'] ?>" width="60" height="60"  /></a>
                                                <h5><?php echo $av['name'] ?></h5>
                                                <span><a href="javascript:attremove(<?php echo $av['id'] ?>);">删除</a></span>
                                            </li>
                                            <?php
                                        }
                                    }
                                    ?>

                                </ul>
                            </div>

                        </dd>
                    </dl>
                    <br />
                    <dl class="online_dl">
                        <dt>公司成立日期：</dt>
                        <dd>
                            <input type="text" name="establishment_time" id="establishment_time" value="<?php echo date('Y-m-d H:i:s', $guarantee['establishment_time']); ?>" onfocus="WdatePicker()" class="Wdate" style="z-index: 0;"/>
                        </dd>
                    </dl>
                    <br />
                    <dl class="online_dl">
                        <dt>开始合作时间：</dt>
                        <dd>
                            <input type="text" name="collaboration_time" id="collaboration_time" value="<?php echo date('Y-m-d H:i:s', $guarantee['collaboration_time']); ?>" onfocus="WdatePicker()" class="Wdate" style="z-index: 0;"/>
                        </dd>
                    </dl>
                    <br />
                    <dl class="online_dl">
                        <dt>公司简介：</dt>
                        <dd>
                            <script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
                            <script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.js"></script>
                            <script type="text/javascript" charset="utf-8">
                                var editor = new baidu.editor.ui.Editor();
                                editor.render('introduction');  //editor为编辑器容器的id
                            </script>
                            <textarea name="introduction" id="introduction" style="width:800px;">
<?php echo $guarantee['introduction']; ?>
                            </textarea>
                        </dd>
                    </dl>



                    <div id="fengxian" <?php if ($guarantee['type'] == 3) { ?>style="display:none;"<?php } ?>>
                        <dl class="online_dl" >
                            <dt>风险控制措施：</dt>
                            <dd>
                                <textarea name="risk_measures" id="risk_measures" style="width:800px; height:120px;"><?php echo $guarantee['risk_measures']; ?></textarea>
                            </dd>
                        </dl>
                        <dl class="online_dl">
                            <dt>抵押物信息：</dt>
                            <dd>
                                <textarea name="collateral" id="collateral" style="width:800px; height:120px;"><?php echo $guarantee['collateral']; ?></textarea>
                            </dd>
                        </dl>
                    </div>
                    <div id="baozhen" <?php if ($guarantee['type'] != 3) { ?>style="display:none;"<?php } ?>>
                        <dl class="online_dl">
                            <dt>保证函：</dt>
                            <dd>
                                <textarea name="letter_guarantee" id="letter_guarantee" style="width:800px; height:120px;"><?php echo $guarantee['letter_guarantee']; ?></textarea>
                            </dd>
                        </dl>
                    </div>
                    <div class="payment_btm">
                        <input type="submit" value="提交"  class="btn_b"/>
                    </div>
                </form>
            </div>


        </div>
    </div>
    <!-- Admin_Right End -->
</div>
<!-- admin_main end -->


<div class="user_list_con" id="grarantee_dialog" style="display:none;">
    <div id="grarantee_dialog_msg" style="text-align:center;color:red">&nbsp;</div>
    <iframe name="iframe" id="iframe" style="display:none;"></iframe>
    <form id="upload_form"  action="/ychadmin/guarantee/doupload"  enctype="multipart/form-data" method="post" target="iframe">
        <div class="user_right_border">
            <p style="color: red;">必须是本人 真实 有效的相关资料！（格式:jpg|png 最大:512K  最高:3000px  最宽:2048px） </p>
        </div>

        <div class="payonline_form">

            <dl class="online_dl" style="height:20px;">
                <dt>上传资料：</dt>
                <dd>
                    <input type="file" name="litpic" />
                </dd>
            </dl>
            <br />
            <dl class="online_dl" style="height:20px;">
                <dt>资料类型：</dt>
                <dd>
                    <select style="width: 160px;" name="type_id">
                        <option value="0">--请选择资料类型--</option>
                        <?php foreach ($type_list as $key => $val) { ?>
                            <option value="<?php echo $key; ?>"><?php echo $val; ?></option>
<?php } ?>
                    </select>
                </dd>
            </dl>
            <br />
            <dl class="online_dl" style="height:20px;">
                <dt>备注说明：</dt>
                <dd>
                    <textarea id="verify_remark" name="verify_remark" style="width: 400px;height: 150px;"></textarea>
                </dd>
            </dl>
        </div>
    </form>
</div>

<script type="text/javascript">

    function add_att() {
        $("#grarantee_dialog").dialog({
            width: 600,
            height: 400,
            modal: false, //蒙层（弹出会影响页面大小）
            title: '添加证明资料',
            buttons: {"提交": function () {
                    form_submit();
                }, "关闭": function () {
                    $(this).dialog("close");
                }}
        });
    }

    var att_arr = [];//定义一个数组
    function form_submit() {
        var options = {
            url: '/ychadmin/guarantee/doupload',
            clearForm: true,
            resetForm: true,
            beforeSubmit: checkForm,
            dataType: "json",
            type: "post",
            contentType: "multipart/form-data",
            success: function (ret) {
                if (ret.url == 'error') {
                    alert(ret.msg);
                } else {
                    $("#grarantee_dialog").dialog("close");
                    $("#guarantee_att").append('<li id="att_litpic_' + ret.msg.id + '"><a target="_blank" href="/' + ret.msg.litpic + '"><img src="/' + ret.msg.litpic + '" width="60" height="60"  /></a><h5>' + ret.msg.name + '</h5><span><a href="javascript:attremove(' + ret.msg.id + ');">删除</a></span></li>');
                    att_arr.push(ret.msg.id);
                    $("#att_id").val(att_arr);
                }

            }
        };

        $("#upload_form").ajaxSubmit(options);
        return false;
    }

    function checkForm() {
        return true;
    }

    $(document).ready(function () {
<?php if (isset($guarantee) && $guarantee['province'] > 0) { ?>
            getArea(0,<?php echo $guarantee['province']; ?>, 'province');
            getArea(<?php echo $guarantee['province']; ?>,<?php echo $guarantee['city']; ?>, 'city');
<?php } else { ?>
            getArea(0, '', 'province');
<?php } ?>
    });

    function changeCity(a, obj) {
        var msg = "<option value=''>请选择</option>";
        if (a != '') {
            getArea(a, '', obj);
            if (obj == 'city') {
                $("#area").html(msg);
            }
        } else {
            if (obj == 'city') {
                $("#city").html(msg);
                $("#area").html(msg);
            }
        }

    }
    function getArea(pid, selected, obj) {
        $.ajax({
            type: "POST",
            url: "/area/get_option",
            data: "pid=" + pid + "&selected=" + selected,
            success: function (msg) {
                $("#" + obj).html(msg);
            },
            dataType: "text"
        });
    }

    function attremove(id) {
        $.ajax({
            type: "get",
            url: '/ychadmin/guarantee/del_att/' + id,
            success: function (ret) {
                $("#att_litpic_" + id).remove();
            },
            dataType: "json"
        });
    }

    function changeType() {
        var type = $("#type").val()
        if (type == 3) {
            $("#baozhen").show();
            $("#fengxian").hide();
        } else {
            $("#fengxian").show();
            $("#baozhen").hide();
        }
    }

</script>
</body>
</html>
